let fs = require('fs');
let path = require('path');

let content = "asdasdasdasdasdasdasd"
let fileName = 'test.txt'
let filePath = path.resolve(__dirname, fileName)

let callback = err => {
    if (err) {
        console.log(err)
    } else {
        console.log('ok')
    }
}
fs.writeFile('test.txt', content, { flag: "w", encoding: 'utf-8' }, callback)



function writefs(path, content) {
    return new Promise((resolve, reject) => {
        fs.writeFile(path, content, { flag: "a", encoding: 'utf-8' }, (err) => {
            if (err) {
                reject(err)
            } else {
                resolve('ok')
            }
        })
    })
}

async function writeFileList() {
    let content = "01"
    let fileName01 = 'test01.txt'
    let filePath01 = path.resolve(__dirname, fileName01)
    let res = await writefs(filePath01, content + '01\n');
    console.log(res)

    res = await writefs(filePath01, content + '02\n');
    console.log(res)

    res = await writefs(filePath01, content + '03\n');
    console.log(res)
    // let fileName02 = 'test02.txt'
    // let filePath02 = path.resolve(__dirname, fileName02)
    // res = await writefs(filePath02, content + '02');
    // console.log(res)


    // let fileName03 = 'test03.txt'
    // let filePath03 = path.resolve(__dirname, fileName03)
    // res = await writefs(filePath03, content + '03');
    // console.log(res)

}
writeFileList()